home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / mmgr / MM_FindPirates.lha / Rexx / MM_FindPirates.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-06-07  |  11.1 KB  |  561 lines

  1. /*
  2.  
  3.                    $VER: MM_FindPirates  1.1  (06/06/98)
  4.  
  5.                        Copyright ©1998 Neil Williams
  6.  
  7.      now2@frost3.demon.co.uk, 2:442/107.0@fidonet, 39:136/1.0@amiganet
  8.                           neil@bleach.demon.co.uk
  9.  
  10. */
  11.  
  12. parse arg args
  13.  
  14. options cache
  15. options failat 99
  16. options results
  17.  
  18. signal on break_c
  19. signal on break_d
  20. signal on break_e
  21. signal on break_f
  22. signal on halt
  23. signal on ioerr
  24. signal on syntax
  25.  
  26. address 'MAILMANAGER'
  27.  
  28.  
  29. Main:
  30.  
  31.     call Init
  32.     call Header
  33.     call Read_Cfg
  34.     call Wait_AreasWindow
  35.  
  36.     call CheckAreas
  37.  
  38. call Quit(0, 'All done.')
  39. exit
  40.  
  41.  
  42. break_c:; break_d:; break_e:; break_f:; halt:
  43.  
  44.     signal off break_c
  45.     signal off break_d
  46.     signal off break_e
  47.     signal off break_f
  48.     signal off halt
  49.  
  50.     return_code        =    5
  51.     error_line    = 0
  52.     error_msg            = 'Execution halted!!!'
  53.     rc                        = 0
  54. signal Exit
  55.  
  56.  
  57. Exit:
  58.  
  59.     select
  60.         when return_code>=40 then error = 'INTERNAL-ERROR:'
  61.         when return_code>=30 then error = 'IO-ERROR:'
  62.         when return_code>=20 then error = 'ERROR:'
  63.         when return_code>=10 then error = 'WARNING:'
  64.         when return_code>=5  then error = 'INFO:'
  65.         otherwise                                    error = ''
  66.     end
  67.  
  68.   call Log()
  69.     call Log('***' strip(error error_msg) '***', '+')
  70.     call Log(,'\')
  71.  
  72.     call setclip('MM_LogPre', system.mm.logpre)
  73.  
  74. exit return_code
  75.  
  76.  
  77.  
  78. Wait_AreasWindow: procedure Expose system.
  79.  
  80.     MM_AreasWin
  81.     if rc=0 then return
  82.  
  83.     bell    = '07'x
  84.     cr        = '0D'x
  85.  
  86.     if Request_Choice('\c\n\1'system.prg.id'\0 is waiting.\n\nPlease go back to the Areas-Window as soon as possible!\n',,
  87.                                         '* _WAIT | _QUIT ', '0 1') then call Quit(5, 'Aborted by user.')
  88.  
  89.     tmp        = 'Waiting for Areas-Window...'
  90.     call writech(STDOUT, bell || tmp || cr)
  91.     call Log(tmp,, 4)
  92.  
  93.     rc    = 1
  94.  
  95.     do while rc~=0
  96.         MM_AreasWin
  97.  
  98.         call writech(STDOUT, bell)
  99.         call Delay(250)
  100.     end
  101.  
  102. return
  103.  
  104.  
  105. Request_Choice: procedure Expose system.
  106.  
  107.     parse arg text, buttons, ret_vals
  108.  
  109.     title    = system.prg.name'-Requester'
  110.     text    = translate(Replace(text, '0A'x, '\n'), '1b'x, '\')
  111.  
  112.     if length(text)<40 then text = center(text, 40)
  113.  
  114.     MM_Requester title 'text' 'buttons'
  115.  
  116.     if rc=0 then rc=words(ret_vals)
  117.  
  118. return compress(word(ret_vals, rc), '_')
  119.  
  120.  
  121. Get_Arg: procedure Expose args system.
  122.  
  123.   arg keyword, mode, old
  124.  
  125.     uargs    = upper(args)
  126.     p            = find(uargs, keyword)
  127.  
  128.     if p=0    then
  129.         do
  130.             p = pos(' 'keyword'=', ' 'uargs)
  131.  
  132.             if p>0 then    args    = overlay(' ', args, p+length(keyword))
  133.  
  134.       p = find(upper(args), keyword)
  135.         end
  136.  
  137.     system.cmdopt.keyword    = p>0
  138.  
  139.     select
  140.         when mode=0    then
  141.             if p>0 then
  142.                 do
  143.                     ret        = 1
  144.                     args    = delword(args, p, 1)
  145.                 end
  146.             else ret    = old
  147.  
  148.         when mode=1 then
  149.             if p>0 then
  150.                 do
  151.                     left    = subword(args, 1, p-1)
  152.                     rest    = subword(args, p+1)
  153.  
  154.                     if left(rest, 1)='"' then    parse var rest . '"'    ret '"'    rest
  155.                     else                                            parse var rest                ret            rest
  156.  
  157.                     args    = strip(left strip(rest))
  158.                 end
  159.             else ret    = old
  160.  
  161.         when mode=2 then
  162.             do
  163.                 if left(args, 1)='"'    then    parse var args . '"'    ret '"'    args
  164.                 else                                                parse var args                ret         args
  165.  
  166.                 if strip(ret)=''            then    ret = old
  167.             end
  168.  
  169.         otherwise exit 99
  170.     end
  171.  
  172.     args    = strip(args)
  173.     ret        = strip(ret, 'b', '" ')
  174.  
  175. return ret
  176.  
  177.  
  178. Get_Version: procedure
  179.  
  180.     parse arg mode
  181.  
  182.     parse value sourceline(3-mode) with . . ver .
  183.     parse var ver tst 'ß' .
  184.  
  185.     if ~datatype(strip(tst, 'b', '/c '), 'N') then
  186.         if ~mode then ver = Get_Version(1)
  187.         else exit 99
  188.  
  189. return ver
  190.  
  191.  
  192. Header:
  193.  
  194.     call Log(,'/')
  195.     call Log('***' system.prg.id '***', '+')
  196.     call Log(' 'system.prg.cr)
  197.     call Log()
  198.  
  199. return
  200.  
  201.  
  202. Init:
  203.  
  204.     system.                        = 0
  205.  
  206.     system.prg.ver        = Get_Version(0)
  207.     system.prg.name        = 'MM_FindPirates'
  208.     system.prg.id            = system.prg.name 'v'system.prg.ver
  209.     system.prg.cfg        = 'MM:Config/'system.prg.name'.cfg'
  210.     system.prg.cr            = '(c)1998 Neil Williams'
  211.     system.tmpfile        = 'T:'system.prg.name'.tmp'
  212.     system.mm.logpre     = getclip('MM_LogPre')
  213.     system.prg.logpre    = system.mm.logpre'|'
  214.     system.prg.loglevel = 2
  215.     call                                setclip('MM_LogPre', system.prg.logpre)
  216. /*    system.cmdopts        = 'OPTIONS' */
  217.  
  218.     system.config.areas.total = 0
  219.     system.config.foot.total    = 0
  220.     system.config.head.total    = 0
  221.     system.config.allareas        = 0
  222.  
  223.     call Include_Lib('rexxsupport')
  224. return
  225.  
  226.  
  227. Include_Lib: procedure Expose system.
  228.  
  229.     parse arg lib, prio
  230.     if right(upper(lib), 8)~='.LIBRARY' then lib    = lib'.library'
  231.     if prio=''                                                    then prio    = 0
  232.  
  233.     if ~show('l', lib) then
  234.         if ~addlib(lib, prio, -30, 0) then call Quit(20, 'Could not open' lib'!!!')
  235.  
  236. return
  237.  
  238.  
  239. IOerr:
  240.  
  241.     signal off ioerr
  242.  
  243.     return_code        = 20
  244.     error_line    = sigl
  245.     error_msg            = 'IO-error' rc 'at line' sigl '['errortext(rc)']')
  246.     rc                        = 0
  247. signal Exit
  248.  
  249.  
  250. Log: procedure Expose system.
  251.  
  252.     parse arg text, pre, level
  253.  
  254.     if ~datatype(level, 'N') then level = system.prg.loglevel
  255.  
  256.     tmp        = word('PRG MM', (pre~='')+1)
  257.     text    = system.tmp.logpre || pre' 'text
  258.  
  259.     MM_WriteLog 'text' level
  260. return
  261.  
  262.  
  263.  
  264.  
  265. Quit:
  266.  
  267.     parse arg return_code, error_msg
  268.  
  269.     error_line    = 0
  270.     rc                        = 0
  271. signal Exit
  272.  
  273.  
  274. Read_Cfg: procedure Expose system.
  275.  
  276.     MM_ReadStem system.prg.cfg 'cfg'
  277.     if RC~=0 then call Quit(31, 'Unable to read' system.prg.cfg'!!!')
  278.  
  279.     call Log('Reading config...')
  280.  
  281.     cnt    = 0
  282.  
  283.     do l=0 to cfg.count-1
  284.         parse value strip(translate(cfg.l, ' ', '9'x)) with key args ';' .
  285.         key        = upper(strip(key))
  286.         args    = strip(args)
  287.  
  288.         select
  289.             when key=''                then iterate
  290.  
  291.             when key='#ALLAREAS'        then    system.config.allareas = 1
  292.  
  293.             when key='#AREA'                then    call Add_Area( args )
  294.             when key='#FOOTER'            then    call Add_Foot( args )
  295.             when key='#HEADER'            then    call Add_Head( args )
  296.  
  297.             otherwise say '*** CFG-ERROR: Unknown keword "'key'" at line' l'!!!'
  298.         end
  299.  
  300.         cnt    = cnt+1
  301.     end
  302.  
  303. return
  304.  
  305.  
  306. /* add an area to search
  307.  */
  308. Add_Area: procedure Expose system.
  309.  
  310.     parse arg area
  311.  
  312.     i = system.config.areas.total
  313.     system.config.areas.i = area
  314.     system.config.areas.total = system.config.areas.total+1
  315.  
  316. return
  317.  
  318.  
  319. /* add a line to look for in the footer of the msg
  320.  */
  321. Add_Foot: procedure Expose system.
  322.  
  323.     parse arg txt
  324.  
  325.     i = system.config.foot.total
  326.     system.config.foot.i = txt
  327.     system.config.foot.total = system.config.foot.total+1
  328.  
  329. return
  330.  
  331.  
  332. /* add a line to look for in the kludges/header
  333.  */
  334. Add_Head: procedure Expose system.
  335.  
  336.     parse arg txt
  337.  
  338.     i = system.config.head.total
  339.     system.config.head.i = txt
  340.     system.config.head.total = system.config.head.total+1
  341.  
  342. return
  343.  
  344.  
  345.  
  346. Replace: procedure
  347.  
  348.     parse arg string, new, old
  349.  
  350.     do while index(string, old) ~= 0
  351.         interpret "parse var string l '"old"' r"
  352.         string = l || new || r
  353.     end
  354.  
  355. return string
  356.  
  357.  
  358. Syntax:
  359.  
  360.     signal off syntax
  361.  
  362.     return_code        = 40
  363.     error_line    = sigl
  364.     error_msg            = 'Syntax-error' rc 'at line' sigl '['errortext(rc)']'
  365.     rc                        = 0
  366. signal Exit
  367.  
  368.  
  369. Usage:
  370.  
  371.     rx.            = ''
  372.     rx.0.0    = '[rx] '
  373.     rx.0.1    = '[.rexx]'
  374.     m                =    pos('/e', system.prg.ver)>0
  375.  
  376.     say
  377.     say 'Usage:' rx.m.0 || system.prg.name || rx.m.1 system.cmdopts
  378.     say
  379. call Quit(0, 'Usage requested.')
  380.  
  381.  
  382. CheckAreas: procedure Expose system.
  383.  
  384. /* trace ?all */
  385.  
  386.     do i = 0 to system.config.areas.total-1
  387.  
  388.         MM_SearchMsgs system.config.areas.i 'msgs' '#?' '#?' '#?' '!SENT'
  389.  
  390.         if RC = 0 then do
  391.  
  392.             do j = 0 to msgs.count-1
  393.  
  394.                 MM_ReadMsg system.config.areas.i msgs.j 'readmsg'
  395.  
  396.                 foundf.count = 0
  397.                 foundh.count = 0
  398.  
  399.                 do k = 0 to readmsg.foot.count
  400.                     if left( readmsg.foot.k, 1 ) = '1'x then do
  401.                         readmsg.foot.k = right( readmsg.foot.k, length( readmsg.foot.k )-1 )
  402.                     end
  403.                 end
  404.  
  405.                 do k = 0 to readmsg.head.count
  406.                     if left( readmsg.head.k, 1 ) = '1'x then do
  407.                         readmsg.head.k = right( readmsg.head.k, length( readmsg.head.k )-1 )
  408.                     end
  409.                 end
  410.  
  411.                 if system.config.foot.total ~= 0 then do
  412.                     do k = 0 to system.config.foot.total-1
  413.                         MM_SearchInStem readmsg.foot 'foundf' '"'system.config.foot.k'"' 'STR'
  414.                     end
  415.                 end
  416.  
  417.                 if system.config.head.total ~= 0 then do
  418.                     do k = 0 to system.config.head.total-1
  419.                         MM_SearchInStem readmsg.head 'foundh' '"'system.config.head.k'"' 'STR'
  420.                     end
  421.                 end
  422.  
  423.                 /* found any?  the counts will be greater than 0 if we have */
  424.                 if ( (foundf.count > 0) | (foundh.count > 0) ) then do
  425.  
  426.                     boss = FindBoss( readmsg.fromaddr )
  427.  
  428.                     call Log( 'Found a pirate!' )
  429.                     call Log( ' Area: 'system.config.areas.i' Msg Nº: 'msgs.j )
  430.                     call Log( ' From: 'readmsg.from' <'readmsg.fromaddr'> Boss: 'boss )
  431.  
  432.                     MM_GetNodelistNode boss 'nodestem'
  433.  
  434.                     /* this needs to be put into the config file, with % codes for features */
  435.  
  436.                     drop outmsg.
  437.  
  438.                     outmsg.0 = 'Hello '|| nodestem.sysop ||','
  439.                     outmsg.1 = ''
  440.                     outmsg.2 = 'This is an automatically generated message.  It would appear'
  441.                     outmsg.3 = 'that a system which is under your responsibility is using'
  442.                     outmsg.4 = 'pirated software.  This is illegal, immoral and violates both'
  443.                     outmsg.5 = 'FidoNet and AmigaNet policy.  The evidence is included below,'
  444.                     outmsg.6 = 'with the important lines highlighted.  The actual message has'
  445.                     outmsg.7 = 'been trucated to 20 lines.'
  446.                     outmsg.8 = ''
  447.                     outmsg.9 = 'Author:    'readmsg.from ' ' readmsg.fromaddr
  448.                     outmsg.10 = 'Addressee: 'readmsg.to
  449.                     outmsg.11 = 'Subject:   'readmsg.subj
  450.                     outmsg.12 = 'Area:      'system.config.areas.i
  451.                     outmsg.13 = 'Date:      'readmsg.date
  452.                     outmsg.14 = ''
  453.                     outmsg.15 = '-------------- BEGINNING OF INCLUDED MESSAGE  ---------------'
  454.                     outmsg.count = 16
  455.  
  456.                     MM_WriteStem system.tmpfile outmsg
  457.                     MM_WriteStem system.tmpfile readmsg.head APPEND
  458.  
  459.                     if readmsg.text.count > 20-1 then do
  460.                         readmsg.text.count = 20
  461.                         alt = 1
  462.                     end
  463.                     else alt = 0
  464.  
  465.                     MM_WriteStem system.tmpfile readmsg.text APPEND
  466.  
  467.                     if alt = 1 then do
  468.                         outmsg.0 = ''
  469.                         outmsg.1 = '[...]'
  470.                         outmsg.2 = ''
  471.                         outmsg.count = 3
  472.  
  473.                         MM_WriteStem system.tmpfile outmsg APPEND
  474.                     end
  475.  
  476.                     MM_WriteStem system.tmpfile readmsg.foot APPEND
  477.  
  478.                     outmsg.0 = '----------------- END OF INCLUDED MESSAGE  ------------------'
  479.                     outmsg.1 = ''
  480.                     outmsg.count = 2
  481.                     MM_WriteStem system.tmpfile outmsg APPEND
  482.  
  483.                     outmsg.0 = '----------- BEGINNING OF ANALYSED RELEVANT DATA -------------'
  484.                     outmsg.count = 1
  485.                     MM_WriteStem system.tmpfile outmsg APPEND
  486.  
  487.                     MM_WriteStem system.tmpfile foundh APPEND
  488.                     MM_WriteStem system.tmpfile foundf APPEND
  489.  
  490.                     outmsg.0 = '-------------- END OF ANALYSED RELEVANT DATA ----------------'
  491.                     outmsg.1 = ''
  492.                     outmsg.count = 2
  493.                     MM_WriteStem system.tmpfile outmsg APPEND
  494.  
  495.                     MM_GetNearestAddr boss myaddr
  496.  
  497.                     matrix = Get_MailArea( boss )
  498.  
  499.                     wmsg.from = system.prg.name
  500.                     wmsg.fromaddr = myaddr
  501.                     wmsg.to = nodestem.sysop
  502.                     wmsg.toaddr = boss
  503.                     wmsg.subj = 'URGENT! Illegal activities!'
  504.                     wmsg.flags = 'PVT RRR'
  505.                     wmsg.file = system.tmpfile
  506.  
  507.                     MM_WriteMsg matrix wmsg
  508.  
  509.                 end /* if found pirate */
  510.  
  511.             end /* do j msgs */
  512.  
  513.         end /* if RC = 0 */
  514.         else do
  515.             call Log( 'Unknown area '|| system.config.areas.i )
  516.         end
  517.  
  518.     end /* do i areas */
  519.  
  520. return
  521.  
  522.  
  523. /* This was writen by Tomasz Nidecki - it finds either the boss node of a point
  524.  * or the NC of the net a SysOp (point = 0) is in.
  525.  */
  526.  
  527. FindBoss: PROCEDURE
  528.  
  529. PARSE ARG zone ':' net '/' node '.' point '@' domain
  530.  
  531. IF point ~= '0' THEN
  532. DO
  533.   BossNode = zone':'net'/'node'.0@'domain
  534. END
  535. ELSE
  536. DO
  537.   BossNode = zone':'net'/0.0@'domain
  538. END
  539.  
  540. RETURN BossNode
  541.  
  542.  
  543.  
  544. /* This was taken from MM_Flame.rexx
  545.  * It tried to match an address to a MATRIX/Netmail area.
  546.  */
  547. Get_MailArea: procedure Expose system.
  548.  
  549.     arg . '@' domain
  550.  
  551.     MM_GetAreas 'tmp' 'MAIL'
  552.  
  553.     do n=0 to tmp.count-1
  554.         MM_GetAreaInfo tmp.n 'info'
  555.         parse value upper(info.addr) with . '@' dmn
  556.  
  557.         if domain=dmn then return tmp.n
  558.     end
  559.  
  560. return tmp.0
  561.